package com.fr.chart;

import com.fr.base.FCloneable;
import com.fr.base.Style;
import com.fr.base.core.GraphHelper;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.base.equals.Equals;
import com.fr.chart.core.glyph.ChartGlyph;
import com.fr.data.ChartData;
import com.fr.data.ChartDataModel;
import com.fr.data.core.define.FilterDefinition;
import com.fr.dialog.NameObject;
import com.fr.report.io.xml.ReportXMLUtils;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.geom.Rectangle2D.Double;
import java.awt.geom.RoundRectangle2D.Double;
import java.util.ArrayList;
import java.util.List;

public class ChartCollection extends ChartLayout
{
  private static final long serialVersionUID = 1265398996017104404L;
  public static final String XML_TAG = "CC";
  private List nameObjectList = new ArrayList();
  private FilterDefinition filterDefinition;

  public void addChart(Chart paramChart)
  {
    addNamedChart("Default", paramChart);
  }

  public void addNamedChart(String paramString, Chart paramChart)
  {
    this.nameObjectList.add(new NameObject(paramString, paramChart));
  }

  public int getChartSize()
  {
    return this.nameObjectList.size();
  }

  public String getChartName(int paramInt)
  {
    return ((NameObject)this.nameObjectList.get(paramInt)).getName();
  }

  public Chart getChart(int paramInt)
  {
    return ((Chart)((NameObject)this.nameObjectList.get(paramInt)).getObject());
  }

  public void removeAllCharts()
  {
    this.nameObjectList.clear();
  }

  public void setFilterDefinition(FilterDefinition paramFilterDefinition)
  {
    this.filterDefinition = paramFilterDefinition;
  }

  public FilterDefinition getFilterDefinition()
  {
    return this.filterDefinition;
  }

  public Chart getSelectedChart()
  {
    int i = Math.max(0, getSelectedIndex());
    return (((i >= 0) && (i < getChartSize())) ? getChart(i) : null);
  }

  public ChartPainter createChartPainter(ChartData paramChartData)
  {
    ChartPainter localChartPainter = new ChartPainter();
    int i = 0;
    int j = getChartSize();
    while (i < j)
    {
      localChartPainter.addNamedGlyph(getChartName(i), getChart(i).createGlyph(paramChartData));
      ++i;
    }
    localChartPainter.setSelectedIndex(getSelectedIndex());
    localChartPainter.setColumns(getColumns());
    return localChartPainter;
  }

  public void paint(Graphics paramGraphics, int paramInt1, int paramInt2, Style paramStyle)
  {
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    if (getSelectedChart() == null)
      return;
    ChartData localChartData = ChartDataModel.getChartData(getSelectedChart().getPlot());
    ChartGlyph localChartGlyph = getSelectedChart().createGlyph(localChartData);
    Image localImage = localChartGlyph.toImage(paramInt1, paramInt2);
    if (localChartGlyph.isRoundBorder())
      localChartGlyph.setBounds(new RoundRectangle2D.Double(0.0D, 0.0D, paramInt1, paramInt2, 10.0D, 10.0D));
    else
      localChartGlyph.setBounds(new Rectangle2D.Double(0.0D, 0.0D, paramInt1, paramInt2));
    localChartGlyph.draw(localGraphics2D);
    GraphHelper.paintImage(localGraphics2D, paramInt1, paramInt2, localImage, Style.getInstance(), 1, paramInt1, paramInt2);
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isAttr())
      removeAllCharts();
    if (paramXMLableReader.isChildNode())
    {
      String str = paramXMLableReader.getTagName();
      if ("Chart".equals(str))
      {
        Chart localChart = new Chart();
        addNamedChart(paramXMLableReader.getAttr("name"), localChart);
        paramXMLableReader.readXMLObject(localChart);
      }
      else if (str.endsWith("Definition"))
      {
        this.filterDefinition = ReportXMLUtils.readDefinition(paramXMLableReader);
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    super.writeXML(paramXMLPrintWriter);
    int i = 0;
    int j = getChartSize();
    while (i < j)
    {
      paramXMLPrintWriter.startTAG("Chart").attr("name", getChartName(i));
      getChart(i).writeXML(paramXMLPrintWriter);
      paramXMLPrintWriter.end();
      ++i;
    }
    if (this.filterDefinition != null)
      this.filterDefinition.writeXML(paramXMLPrintWriter);
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    ChartCollection localChartCollection = (ChartCollection)super.clone();
    localChartCollection.nameObjectList = new ArrayList(getChartSize());
    int i = 0;
    int j = getChartSize();
    while (i < j)
    {
      localChartCollection.addNamedChart(getChartName(i), (Chart)getChart(i).clone());
      ++i;
    }
    if (this.filterDefinition != null)
      localChartCollection.filterDefinition = ((FilterDefinition)this.filterDefinition.clone());
    return localChartCollection;
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof ChartCollection))
      return false;
    ChartCollection localChartCollection = (ChartCollection)paramObject;
    if (!(super.equals(localChartCollection)))
      return false;
    if (!(Equals.equals(localChartCollection.filterDefinition, this.filterDefinition)))
      return false;
    if (localChartCollection.nameObjectList.size() != this.nameObjectList.size())
      return false;
    for (int i = 0; i < localChartCollection.getChartSize(); ++i)
    {
      if (!(Equals.equals(localChartCollection.getChart(i), getChart(i))))
        return false;
      if (!(Equals.equals(localChartCollection.getChartName(i), getChartName(i))))
        return false;
    }
    return true;
  }
}